package rmi;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

import log.Logger;

import philosoph.Philosoph;
import table.ITable;
import table.RoundWalkingTable;

public class RMIServerTable extends UnicastRemoteObject implements RMIServerTableInterface {
	private static final long serialVersionUID = 6299783379012050006L;
	
	private ITable<Philosoph> table = null;

	protected RMIServerTable() throws RemoteException {
		super();
	}

	@Override
	public boolean createTable(Logger logger, int seats) throws RemoteException, InterruptedException {
		if(table != null)
			return false;
		
		table = new RoundWalkingTable<Philosoph>(seats, logger);
		logger.log(-1, "Table:\t\t created new Table, with " + (seats >> 1) + " seats");
		return true;
	}

	@Override
	public boolean sitNEat(Philosoph phil) throws RemoteException, InterruptedException {
		if(table == null) {
			System.out.println("Error: Create Table first.");
			return false;
		}
		
		return table.sitNEat(phil);
	}
	
}
